//
//  BaseTableViewController.swift
//  Weibo
//
//  Created by zxy on 2018/11/30.
//  Copyright © 2018 zxy. All rights reserved.
//

import UIKit
class BaseTableViewController: UITableViewController {
    
    //保存访客视图
    var visitorV: VisitorView?
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        NotificationCenter.default.addObserver(self, selector: #selector(mm), name: NSNotification.Name("mm"), object: nil)
    }
    
    @objc func mm(){
        //将view设置为nil，就会重新调用loadView方法
        view = nil
    }
    
    override func loadView() {
        isLogin ? super.loadView() : visitorView()
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(registerDidClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(loginDidClick))
    }

    //没有登录加载访客视图View,覆盖系统View
    private func visitorView(){
        let v = VisitorView()
        v.delegate = self
        view = v
        visitorV = v
    }
}

//MARK:-登录注册点击事件
extension BaseTableViewController:VistorDelegate{
    //注册
    @objc func registerDidClick() {
        print(#function)
    }
    
    //登录
    @objc func loginDidClick() {
         let ctl = OAuthViewController()
         let nav = UINavigationController(rootViewController: ctl)
        present(nav, animated: true, completion: nil)
    }
}
